<form id="addOrUpdateForm" lay-filter="addOrUpdateForm" class="layui-form model-form">

    <input name="id" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">泳池名称</label>
        <div class="layui-input-block">
            <input name="name" class="layui-input" placeholder="请输入泳池名称" lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">泳池状态</label>
        <div class="layui-input-block">
            <select name="state"  lay-verType="tips" lay-verify="required" required>
                <option value="开放">开放</option>
                <option value="关闭">关闭</option>
            </select>

        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">价格</label>
        <div class="layui-input-block">
            <input name="price" class="layui-input" placeholder="请输入泳池价格" lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">产品图片</label>
        <div class="layui-upload" >
            <button type="button" class="layui-btn" id="img">上传图片</button>
            <div class="layui-upload-list" style="padding-left: 108px">
                <img class="layui-upload-img" id="demo1" name="img" style="display:inline-block;max-width:50%;height:auto">
                <p id="demoText"></p>
            </div>
        </div>
        <div id="file-list-group"></div>

    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">泳池备注</label>
        <div class="layui-input-block">
            <input name="mark" class="layui-input" placeholder="请输入泳池备注" lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">泳池深度</label>
        <div class="layui-input-block">
            <input name="deep" class="layui-input" placeholder="请输入泳池深度" lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">泳池面积</label>
        <div class="layui-input-block">
            <input name="area" class="layui-input" placeholder="请输入泳池面积" lay-verType="tips" lay-verify="required" required/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label layui-form-required">维护状态</label>
        <div class="layui-input-block">
            <select name="preserve"  lay-verType="tips" lay-verify="required" required>
                <option value="维护中">维护中</option>
                <option value="已维护">已维护</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item text-right">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        <button class="layui-btn" lay-filter="formSubmitBtn" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'form', 'admin', 'xnUtil', 'xmSelect', 'laydate' , 'upload'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var admin = layui.admin;
        var xnUtil = layui.xnUtil;
        var xmSelect = layui.xmSelect;
        var laydate = layui.laydate;
        var upload = layui.upload;
        var img;



        form.render("select");
        var uploadInst = upload.render({
            elem: '#img'
            ,url: getProjectUrl() + 'sysFileInfo/upload' //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });

            }
            ,done: function(res){

                img = res.data;
                //上传成功的一些操作
                //……
                $('#demoText').html(''); //置空上传失败的状态
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
            //进度条
            ,progress: function(n, elem, e){
                element.progress('demo', n + '%'); //可配合 layui 进度条元素使用
                if(n == 100){
                    layer.msg('上传完毕', {icon: 1});
                }
            }
        });
        var editData = admin.getLayerData('#addOrUpdateForm').data;
        if(editData !== null && editData !== undefined) {
            form.val('addOrUpdateForm', editData);
        }

        /**
         * 表单提交事件
         */
        form.on('submit(formSubmitBtn)', function (data) {
            data.field.img = img;
            layer.load(2);

            var url = editData ? getProjectUrl() + 'pool/edit' : getProjectUrl() + 'pool/add';
            admin.req(url, JSON.stringify(data.field), function(res){
                layer.msg(res.message, {icon: 1, time: 1000}, function () {
                    admin.putLayerData('formOk', true, '#addOrUpdateForm');
                    admin.closeDialog('#addOrUpdateForm');
                });
            }, 'post');
            return false;
        });
    });
</script>
</body>
</html>
